package logic

import (
	"context"

	"go-zero_try/mall/order/rpc/pb/internal/svc"
	"go-zero_try/mall/order/rpc/pb/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryLogic {
	return &QueryLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QueryLogic) Query(in *pb.DelAndQryReq) (*pb.DelAndQryReps, error) {
	u1, err := l.svcCtx.UserModel.FindOne(l.ctx, in.UID)
	msg := ""
	if err == nil {
		msg = "查找成功"
	} else {
		msg = "查无此人"
	}
	return &pb.DelAndQryReps{
		Msg:  msg,
		UID:  u1.Uid,
		Name: u1.Username,
		Age:  u1.Age,
	}, nil
}
